<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>在线下单</title>
    <jsp:include page="../../head.jsp"/>
    <style type="text/css">
        table {
            clear: both;
        }

        ul, li {
            list-style: none;
        }

        .li1 {
            list-style: none;
            float: left;
        }

        .li2 {
            list-style: none;
            float: left;
        }

        .ul1 {
            list-style: none;
            clear: left;
        }

        .div_content {
            display: none;
        }

        .li_content {
            display: none;
        }

        .pointer {
            cursor: pointer;
        }

        .hiddenValue {
            display: none;
        }
    </style>
    <script type="text/javascript"
            src="<s:url value="/js/business/business.js"/>">
    </script>
    <script type="text/javascript">
        // var Btime="${book.confirmTime}";
        // var Ttime="${trial.confirmTime}";
        // var Dtime="${declare.confirmTime}";
        var businessId = "${businessId}";//业务编号ID
        //判断是否是业务查询页面传来的数据
        var identification = "${identification}";
        function getPi(value) {
            var cBook = $('#book').attr('checked');
            var cTrail = $('#trail').attr('checked');
            var cDeclarate = $('#declarate').attr('checked');
            /* if(cDeclarate && cBook && cDeclarate == "checked" && cBook == "checked"){
             $("#contract_no").attr("value",$("#book_pi").val());
             } */
            if (value && value != "最长20个字符") {
                if (cBook == "checked") {
                    $("#book_pi").attr("value", value);
                }
                if (cTrail == "checked") {
                    $("#trial_pi").attr("value", value);
                }
                if (cDeclarate == "checked") {
                    $("#contract_no").attr("value", value);
                }
            }
        }

        //导出报关资料
        function exportCustomsData() {
            var id = "${declare.id }";
            var is_wood_packaging = "${declare.is_wood_packaging}";
            var url = "";
            if (is_wood_packaging == "1") {
//	 		var url = "http://localhost:8075/WebReport/ReportServer?reportlet=declarationPackingList.cpt&id="+id+"";//本机
                url =
                        "http://219.130.222.62:7080/report/ReportServer?reportlet=gtimp/declarationPackingList.cpt&op=write&id="
                        + id + "";
            } else {
                url =
                        "http://219.130.222.62:7080/report/ReportServer?reportlet=gtimp/declarationPackingList_1.cpt&op=write&id="
                        + id + "";
            }

// 	 	var xmlhttp;
// 	 	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
// 	 	  xmlhttp=new XMLHttpRequest(); //创建 XMLHttpRequest 对象
// 	 	  } else {// code for IE6, IE5
// 	 	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); //则创建 ActiveXObject针对IE5，IE6
// 	 	  }
//  		xmlhttp.onreadystatechange=function() {
//  		  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
//  			  // 			document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
//  			  alert("2222");
//  		  } else {
//  			  alert("1111");
//  		  }
// 	 	}
// 	 	xmlhttp.open("GET",url,true);
// 	 	xmlhttp.send();
            window.open(url);
        }

        function exportCustomsDataIn() {
            var id = "${declare.id }";
            var is_wood_packaging = "${declare.is_wood_packaging}";
            var url = "";
            if (is_wood_packaging == "1") {
//	 		var url = "http://localhost:8075/WebReport/ReportServer?reportlet=declarationPackingList.cpt&id="+id+"";//本机
                url =
                        "http://192.168.0.4:7080/report/ReportServer?reportlet=gtimp/declarationPackingList.cpt&op=write&id="
                        + id + "";
            } else {
                url =
                        "http://192.168.0.4:7080/report/ReportServer?reportlet=gtimp/declarationPackingList_1.cpt&op=write&id="
                        + id + "";
            }
            window.open(url);
        }

        $(document).ready(function () {
            var com_type = $("#com_type").val();
            var declareState = $("#declareStateInput").val();
            $("#tabs").tabs({cache: true});
// 		if(Btime!=""||Ttime!=""||Dtime!=""){
// 			$("#sumit").attr('disabled',true);
// 		}else{
// 			$("#sumit").attr('disabled',false);
// 		}
            if (identification == "list") {
                $("#sumit").hide();
                $("#tijiao").hide();
                $("#mrdForm").hide();
                $("#businessForm").find("div").eq(0).hide();
                var bookId = "${book.id}";
                var trialId = "${trial.id}";
                var declareId = "${declare.id}";
                var str = "";
                if (bookId != null && bookId != "") {
                    str += "book.id=" + bookId + "&";
                }
                if (trialId != null && trialId != "") {
                    str += "trial.id=" + trialId + "&";
                }
                if (declareId != null && declareId != "") {
                    str += "declare.id=" + declareId;
                    if ($("#declareStateInput").val() == "DS00" || $("#declareStateInput").val()
                                                                   == "DS03") {
                        $("#sumit1").show();
                        $("#tijiao1").show();
                    } else {
                        $("#sumit1").hide();
                        $("#tijiao1").hide();
                    }
                    if (com_type == "CL") {//客户
                        $("#shenhe").hide();
                    } else if (com_type == "CC") {//供应商
                        $("#sumit1").hide();
                        $("#tijiao1").hide();
                        $("#saveAsModel").hide();
                        if (declareState == "DS02" || declareState == "DS04") {
                            $("#shenhe").hide();
                        } else if (declareState == "DS03") {
                            $("#shenhe").hide();
                        }
                    }
                }
                if (str != null && str != "") {
                    $("#aInSpan").css("display", "inline");
                    document.getElementById("createExl").href = "business-createBusiExl?" + str;
                } else {
                    alert("没有业务需要导出");
                }
                ;
            } else {
// 			$("#sumit").show();
// 			$("#tijiao").show();
                if (declareState == "DS00") {
                    $("#shenhe").hide();
                }
            }
        });

        //保存为常用模板
        function doSaveModel() {
            var trailId = "${trial.id}";
            var declarationId = "${declare.id}";
            jw.dialog({
                          iframe: "<s:url value="/business/prepareSveAsModel"/>",
                          width: 600
                      });
        }

        function saveAsModel(modelName) {
            $.ajax({
                       url: '<s:url value="/business/saveAsModel2.0"/>',
                       data: {id: '${declare.id}', modelName: modelName},
                       method: 'POST',
                       dataType: 'json',
                       success: function (result) {
                           result = $.parseJSON(result);
                           if (result.rs) {
                               alert("保存成功");
                           } else {
                               alert("发生了错误，CODE[" + result.code + "]");
                           }
                       },
                       error: function () {
                           alert("发生了错误，CODE[001]");
                       }
                   });
        }

        //详细页面审核
        function examination() {
            var id = $("#businessInput").val();
            var businessId = $("#businessIdInput").val();
            var iddata = "id=" + id + "&opType=tgsh&businessId=" + businessId;
            $.ajax({
                       cache: false,
                       url: "declaration-checkValidatePass",
                       dataType: "json",
                       data: iddata,
                       success: function (data) {
                           if (!data) {
                               return;
                           }
                           var msg = data.msg ? $.parseJSON(data.msg) : "";
                           if (msg.state == 1) {
                               jw.confirm("确定要该业务通过审核?", function () {
                                              $.ajax({
                                                         cache: false,
                                                         url: "declaration-validatePass",
                                                         dataType: "json",
                                                         data: iddata,
                                                         success: function (data) {
                                                             $("#shenhe").hide();
                                                             jw.alert(msg.msg);

// 								$("#declarationsDataGrid").jqGrid("setGridParam",
// 										{
// 											search : true
// 										// 将jqGrid的search选项设为true
// 										}).trigger("reloadGrid", [ {
// 									page : 1
// 								} ]);
                                                         }
                                                     });
                                          },
                                          function () {
                                              return;
                                          });
                           }
                           else if (msg !== undefined && msg != "" && msg.state == 0) {
                               jw.alert("只有处于待审核状态的业务才可以进行审核操作。");
                           }
                           else {
                               jw.alert(msg.msg);
                           }
                       }
                   });
        }

    </script>
</head>
<body>
<input id="singleTypeInput" value="${singleType}" type="hidden"/>
<input id="businessInput" value="${id }" type="hidden"/>
<input id="businessIdInput" value="${businessId }" type="hidden"/>
<input id="declareStateInput" value="${declare.state }" type="hidden">
<input id="com_type" value="${com_type }" type="hidden"/>
<!-- 用来标志是否是业务查询页面 传过来的数据-->
<input id="identification" value="${identification}" type="hidden"/>
<div id="mrdForm" style="display: none;">
    <table>
        <tr>
            <td>基本资料填写</td>
        </tr>
    </table>
</div>
<form method="post" action="business-edit" id="businessForm">
    <div class="sendSup" style="display: none;">
        <ul>
            <li>
                <ul class="right-aligned">
                    <li class="li1">公司名称：</li>
                    <li class="li1 li1_space"><input type="text" id="company"
                                                     value='${declare.shipper.company}'
                                                     disabled="disabled" name="shipper.company"/>
                    </li>
                    <li class="li1">联系人：</li>
                    <li class="li1 li1_space"><input type="text" id="name"
                                                     value='${declare.shipper.name}'
                                                     disabled="disabled" name="shipper.name"/></li>
                    <li class="li1">联系电话：</li>
                    <li class="li1 li1_space"><input type="text" id="phone"
                                                     value='${declare.shipper.phone}'
                                                     disabled="disabled" name="shipper.phone"/></li>
                    <li class="li1">联系地址：</li>
                    <li class="li1 li1_space"><input type="text" id="address"
                                                     value='${declare.shipper.address}'
                                                     disabled="disabled"
                                                     name="shipper.address"/><input type="hidden"
                                                                                    id="shipId"
                                                                                    value='${declare.shipper.id}'
                                                                                    name="shipper.id"/>
                    </li>
                    <li class="li1">传真：</li>
                    <li class="li1 li1_space"><input type="text" id="fax"
                                                     value='${declare.shipper.fax}'
                                                     disabled="disabled" name="shipper.fax"/></li>
                    <li class="li1">邮箱：</li>
                    <li class="li1 li1_space"><input type="text" id="email"
                                                     value='${declare.shipper.email}'
                                                     disabled="disabled" name="shipper.email"/></li>
                </ul>
            </li>
        </ul>
    </div>
    <div style="clear: both; display: none;">
        <ul>
            <li class="striking" id="busiType">
                <!-- 					订舱 -->
                <input type="checkbox" name="busiType" id="trail" disabled="disabled"
                       <c:if test="${trial.id!=null}">checked="checked"</c:if> />拖车
                <input type="checkbox" name="busiType" id="declarate" disabled="disabled"
                       <c:if test="${declare.id!=null}">checked="checked"</c:if> />
                报关
                <input id="sumit"
                       style="background-color:#94E7FF ;border: 1px solid #6ACCE8 ;cursor: pointer;border-radius: 3px"
                       type="button" value="保存" onclick="updateBiz();"/>
                <input id="tijiao"
                       style="background-color:#FED14C ;border:1px solid #F29A10;cursor: pointer;border-radius: 3px"
                       type='button' value='提交' onclick="summitBiz(businessId);"/>
                <!-- 					<input id="returnBtn" type="button" value="返回" onclick="location.href='business-businessList';" /></li> -->
                <input id="returnBtn"
                       style="background-color:#94E7FF ;border: 1px solid #6ACCE8 ;cursor: pointer;border-radius: 3px"
                       type="button" value="返回" onclick="returnBack();"/>
                <span id="aInSpan" style="display:none;"><a id='createExl' target='_blank'>导出exl</a></span>
        </ul>
    </div>
    <div id="tabs">
        <ul id="liList">
            <c:if test="${book.id!=null}">
                <li><a href="business-booking?book.id=${book.id }">订舱</a></li>
                <input type="hidden" id='bookId' value='${book.id }'/>
            </c:if>
            <c:if test="${trial.id!=null}">
                <li><a href="business-trail?trial.id=${trial.id }">拖车</a></li>
                <input type="hidden" id='trialId' value='${trial.id }'/>
            </c:if>

            <c:if test="${declare.id!=null}">
                <input type="hidden" id='declareId' value='${declare.id }'/>
                <input type="hidden" id='declareId11' value='${declare.is_wood_packaging }'/>
                <li><a href="<s:url value="business-declarationMain?id=${declare.id }"/>">报关基础信息</a>
                </li>
                <li><a href="<s:url value="business-declaration?id=${declare.id }"/>">报关</a></li>
                <li>
                    <a href="<s:url value="business-declarationPackingList?editType=1&id=${declare.id }"/>">装箱单</a>
                </li>
                <li><a href="<s:url value="business-declarationContract?id=${declare.id }"/>">合同</a>
                </li>
                <li><a href="<s:url value="business-declarationInvoice?id=${declare.id }"/>">发票</a>
                </li>
                <c:if test="${declare.is_wood_packaging=='1'.toString()}">
                    <li>
                        <a href="<s:url value="business-noWoodPackaging?id=${declare.id }"/>">无木质包装</a>
                    </li>
                </c:if>
                <li>
                    <input type="button" class="ui-button ui-widget ui-state-default ui-corner-all"
                           value="导出报关资料"
                           onclick="exportCustomsData();"/>
                </li>
                <!-- <li> -->
                <!-- <input type="button" class="ui-button ui-widget ui-state-default ui-corner-all" value="内网导出报关资料" onclick="exportCustomsDataIn();"/> -->
                <!-- </li> -->
            </c:if>
        </ul>
    </div>
</form>
<div id="orderSave" align="center" style="margin-top:10px;">
    <input id="sumit1" class="ui-button ui-widget ui-state-default ui-corner-all" type="button"
           value="保存"
           onclick="updateBiz();"/>
    <input id="tijiao1" class="ui-button ui-widget ui-state-default ui-corner-all" type='button'
           value='提交'
           onclick="summitBiz(businessId);"/>
    <input id="saveAsModel" class="ui-button ui-widget ui-state-default ui-corner-all" type="button"
           value="保存为模板"
           onclick="doSaveModel()"/>
    <input id="shenhe" class="ui-button ui-widget ui-state-default ui-corner-all" type="button"
           value="审核"
           onclick="examination()"/>
    <input id="returnBtn" class="ui-button ui-widget ui-state-default ui-corner-all" type="button"
           value="返回"
           onclick="returnBack();"/>
    <div id="upload_so" style="display:none;">
        SO信息：<span></span><input name="containerInfo.id"
                                 value="${declare.containerInfo.id}"
                                 id="containerInfoId" style="display:none;"/>
    </div>
    <div id="dialog002" style="display:none">
        <form id="uploadAccessoryForm" action="attach/doUpload?type=declare&bill_no=${param.id}"
              enctype="multipart/form-data" method="POST">
            <input type="file" value="选择文件" name="attach"/>
            <input type="submit" vlaue="上传"/>
        </form>
    </div>
</div>
</body>
</html>
